#!/usr/bin/python

import sys
import dbus

def usage_error():
    sys.stderr.write("usage: " + sys.argv[0] + " alert <id> <description>\n" +
 		     "       " + sys.argv[0] + " clear <id>\n")
    sys.exit(1)


bus = dbus.SessionBus()
try:
    conditions = bus.get_object('com.highgateguild.Conditions', '/com/highgateguild/Conditions')
except dbus.DBusException, e:
    sys.stderr.write(str(e))
    sys.stderr.write("\n")
    sys.exit(1)

if len(sys.argv) < 3:
    usage_error()

condition_id = sys.argv[2]

if sys.argv[1] == 'alert':
    description = " ".join(sys.argv[3:])
    conditions.alert(condition_id, description)
    
elif sys.argv[1] == 'clear':
    conditions.clear(condition_id)
    
else:
    usage_error()
